----------------------
------Options---------
----------------------
--[=[
local _G = getfenv(0)
local CreateFrame = CreateFrame;
local CreateFontString = CreateFontString

--Parent, Register
CreateFrame("Frame", "Icetip_OptionsFrame", UIParent);
Icetip_OptionsFrame.name = "Icetip";
InterfaceOptions_AddCategory(Icetip_OptionsFrame);

local cursortype = {
	["鼠标下"] = {val = "CURSOR_BUTTOM", tooltipTitle = "鼠标下部", tooltipText = "以鼠标为锚点,显示在此锚点的下方"},
	["鼠标上"] = {val = "CURSOR_TOP", tooltipTitle = "鼠标上部", tooltipText = "以鼠标为锚点,显示在此锚点的下方"},
	["鼠标左"] = {val = "CURSOR_LEFT", tooltipTitle = "鼠标左部", tooltipText = "以鼠标为锚点,显示在此锚点的下方"},
	["鼠标右"] = {val = "CURSOR_RIGHT", tooltipTitle = "鼠标右部", tooltipText = "以鼠标为锚点,显示在此锚点的下方"},
	["鼠标居中"] = {val = "CURSOR_CENTER", tooltipTitle = "鼠标中间", tooltipText = "以鼠标为锚点,显示在此锚点的下方"},
	["鼠标左上"] = {val = "CURSOR_TOPLEFT", tooltipTitle = "鼠标左上", tooltipText = "以鼠标为锚点,显示在此锚点的下方"},
	["鼠标右上"] = {val = "CURSOR_TOPRIGHT", tooltipTitle = "鼠标右上", tooltipText = "以鼠标为锚点,显示在此锚点的下方"},
	["鼠标左下"] = {val = "CURSOR_BUTTOMLEFT", tooltipTitle = "鼠标左下", tooltipText = "以鼠标为锚点,显示在此锚点的下方"},
	["鼠标右下"] = {val = "CURSOR_BUTTOMRIGHT", tooltipTitle = "鼠标右下", tooltipText = "以鼠标为锚点,显示在此锚点的下方"},
}

--创建子模板以及标题, subText
function Icetip_OptionsFrame:CreateSubTab(panelName, panelTitle, subText)
	local subPanel = "Icetip_OptionsFrame_"..panelName;
	local subFrame = CreateFrame("Frame", subPanel, InterfaceOptionsFramePanelContainer);
	local subPanelTitle = subPanel.."Title"
	subPanelTitle = subFrame:CreateFontString(nil, "ARTWORK", "BossEmoteNormalHuge");
	subPanelTitle:SetJustifyH("LEFT");
	subPanelTitle:SetJustifyV("TOP");
	subPanelTitle:SetPoint("TOPLEFT", 12, -10);
	subPanelTitle:SetText("|cFF34A2F7"..panelTitle.."|r");

	if (subText) then
		subPanelSubText = subFrame:CreateFontString(nil, "ARTWORK", "GameFontNormal");
		subPanelSubText:SetJustifyH("LEFT");
		subPanelSubText:SetJustifyV("TOP");
		subPanelSubText:SetPoint("TOPLEFT", 16, -42);
		subPanelSubText:SetText("   "..subText);
	end

	--register
	subFrame.name = panelTitle;
	subFrame.parent = "Icetip";
	InterfaceOptions_AddCategory(subFrame);
end

--[[
	Create Sub Tab Panel
]]--

Icetip_OptionsFrame:CreateSubTab("Gernal", "综合", "设置鼠标提示天赋显示, 立体化等等增强.")
Icetip_OptionsFrame:CreateSubTab("Color", "颜色", "设置鼠标提示背景, 显示字体颜色")
Icetip_OptionsFrame:CreateSubTab("Status", "状态条", "设置鼠标提示状态条的材质, 位置以及数值")
Icetip_OptionsFrame:CreateSubTab("Anchor", "提示位置", "设置鼠标提示位置.")


--[[
	set anchor 
]]--
do
	local f = getglobal("Icetip_OptionsFrame_Anchor")
	CreateFrame("Frame", "Icetip_OptionsFrame_AnchorCursor", f, "OptionFrameBoxTemplate");
	local box = Icetip_OptionsFrame_AnchorCursor;
	box:SetPoint("TOPLEFT", 16, -80);
	box:SetWidth(355);
	box:SetHeight(140);
	box:SetBackdropBorderColor(0.4, 0.4, 0.4)
	box:SetBackdropColor(0.15, 0.15, 0.15)
	Icetip_OptionsFrame_AnchorCursorTitle:SetText("鼠标提示显示位置设置(指向单位)")--fix
		--创建dropdown
		local Icetip_CursorTitle = box:CreateFontString(nil, "ARTWORK", "GameFontNormal");
		Icetip_CursorTitle:SetJustifyH("TOP");
		Icetip_CursorTitle:SetJustifyV("LEFT");
		Icetip_CursorTitle:SetPoint("TOPLEFT", 8, -12);
		Icetip_CursorTitle:SetText("选择位置: ");

		CreateFrame("Frame", "Icetip_CursorDropdown", box, "UIDropDownMenuTemplate");
		Icetip_CursorDropdown:SetPoint("TOPRIGHT", -30, -12);
		Icetip_CursorDropdown:SetHitRectInsets(16, 16, 0, 0);
		UIDropDownMenu_SetWidth(180, Icetip_CursorDropdown);
		UIDropDownMenu_EnableDropDown(Icetip_CursorDropdown);

			--["unitOffsetX"] = 0,
			--["unitOffsetY"] = 0,
		
	
	CreateFrame("Frame", "Icetip_OptionsFrame_AnchorFrame", f, "OptionFrameBoxTemplate");
	local box = Icetip_OptionsFrame_AnchorFrame;
	box:SetPoint("TOPLEFT", 16, -250);
	box:SetWidth(355);
	box:SetHeight(140);
	box:SetBackdropBorderColor(0.4, 0.4, 0.4)
	box:SetBackdropColor(0.15, 0.15, 0.15)
	Icetip_OptionsFrame_AnchorFrameTitle:SetText("鼠标提示显示位置设置(指向frame)")--fix
end




function Icetip_Options_Init()


	
	Icetip_CursorDropdown.initialize = Icetip_CursorDropdown_Initialize
	local unitanchor = IcetipDB.Position["unitAnchor"];
	UIDropDownMenu_SetSelectedValue(Icetip_CursorDropdown, unitanchor)
	for k, v in pairs(cursortype) do
		if (v.val == unitanchor) then
			Icetip_CursorDropdownText:SetText(k)
			Icetip:Debug(k);
		end
	end
end


function Icetip_CursorDropdown_Initialize()
	local info = {}
	for k, v in pairs(cursortype) do
		info.text = k;
		info.val = v.val;
		info.checked = nil;
		info.owner = this:GetParent()
		info.tooltipTitle = v.tooltipTitle;
		info.tooltipText = v.tooltipText;
		info.func = Icetip_CursorCheck;
		UIDropDownMenu_AddButton(info);
	end
end

function wsCC_BuffPointDropDown_OnClick()
	UIDropDownMenu_SetSelectedValue(this.owner, this.value);
	IcetipDB.Position["unitAnchor"] = this.value;
end

Icetip_OptionsFrame:RegisterEvent("VARIABLES_LOADED");
Icetip_OptionsFrame:SetScript("OnEvent", Icetip_Options_Init);
Icetip_OptionsFrame:SetScript("OnShow",  Icetip_Options_OnShow);
]=]--
--[[  
	Slash  
]]--
local function Icetip_Slash(context)
	Icetip:SlashCmd(context.Slash_Arg)
end

function Icetip:SlashCmd(Icemsg)
	local db = IcetipDB
	if (Icemsg == "") then
		Icetip:Debug("欢迎使用小巧玲珑的IceTip.");
		Icetip:Debug("|cFF34A2F7-reset|r    重置配置");
		Icetip:Debug("|cFF34A2F7-gui|r      打开设置界面");
		Icetip:Debug("|cFF34A2F7-mask|r      设置3D模式");
		Icetip:Debug("|cFF34A2F7-target|r      显示目标");
		Icetip:Debug("|cFF34A2F7-Talented|r      显示目标");
		
	end

	if (Icemsg == "reset") then
		IcetipDB = Icetip.GetDefault();
		self:Debug("重置");
	end

	if (Icemsg == "gui") then
		InterfaceOptionsFrame_OpenToFrame("Icetip")
	end

	if (Icemsg == "mask") then
		if db.VVMask then
			db.VVMask = false
			Icetip:VVMask():Hide()
			Icetip:Debug("禁用")
		else
			db.VVMask = true
			Icetip:VVMask():Show()
			Icetip:Debug("启用")
		end
	end

	if (Icemsg == "target") then
		if db.DisTarget then
			db.DisTarget = false
			Icetip:Debug("禁用")
		else
			db.DisTarget = true
			Icetip:Debug("启用")
		end
	end

	if (Icemsg == "talent") then
		if db.Talented then
			db.Talented = false
			Icetip:Debug("禁用")
		else
			db.Talented = true
			Icetip:Debug("启用")
		end
	end

end


Icetip.SlashCMDBlock = {	
	RequestTypes = {"SlashCommand"},
	SlashCommands = {"icetip", "/it"},
	Commands = {
		{Function = Icetip_Slash},
	}
}
Icetip:Add(EVA.Block:New(Icetip.SlashCMDBlock))